package com.fsoft.core.dict.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fsoft.core.Global;
import com.fsoft.core.common.QueryParam;
import com.fsoft.core.common.base.contorller.BaseController;
import com.fsoft.core.dict.entity.SysDictItem;
import com.fsoft.core.dict.service.SysDictItemService;
import com.fsoft.core.utils.RetVo;
import com.fsoft.core.utils.tree.Tree;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

/**
 * 字典API查询
 * @author Fish
 * @date 2021-04-18
 * @email it.fish2010@foxmail.com
 * @copyright ©2015-2021
 * @Company 广西自贸区佳成软件有限责任公司
 */
@Controller
@RequestMapping("/dict")
public class SysDictApiController extends BaseController {
	@Autowired
	private SysDictItemService service;
	private String key = "dictId";

	/***
	 * 获取物品分类
	 * @author Fish
	 * @date 2021-04-18
	 * @param params
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "/findClassItem", method = RequestMethod.POST)
	public RetVo findClassItem(@RequestParam Map<String, Object> params) throws Exception {
		QueryParam query = new QueryParam(params);
		Page<SysDictItem> page = PageHelper.startPage(query.getPage(), query.getLimit());
		query.put(key, Global.DICT_KEY_WUPFL);
		List<SysDictItem> list = service.findList(query);
		return RetVo.ok(page.getTotal(), list);
	}

	@ResponseBody
	@RequestMapping(value = "/findClassTree", method = RequestMethod.POST)
	public RetVo findClassTree(@RequestParam Map<String, Object> params) throws Exception {
		QueryParam query = new QueryParam(params);
		query.put(key, Global.DICT_KEY_WUPFL);
		List<Tree> list = service.findTrees(query);
		return RetVo.ok(list);
	}
}
